const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sdsj:'',
    sdsjbg:'',
    scsj:'',
    scsjbg:'',
    cklxfs:'color: #fff',
    cklxfsbg:'background: #0cc783;border:solid 1px #0cc783',
    fenxiang:'color: #fff',
    fenxiangbg:'background: #0cc783;border:solid 1px #0cc783',
    title:'模组厂绑定COG压排设备 贴合设备低',
    time:'2018-03-14',
    gqInfo:[],
    phonelist:[],
    gqid:0,
    showModal: false,
    showModaltel: false,
    LoginUserRankName:'',
    AllLookNum:'',
    HaveLookNum:'',
    NextRankName:'',
    ComAddress:'',
    ComName:'',
    InfoContent:'',
    Mobile:'',
    showModalty:false, 
    showModaltyContent:'',
    LinkMan:'',
    ComPhone:'',
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    is_vod:0,
    IsVideo:0, 
    is_show:true,
    imgUrl:app.data.imgUrl
  },
  sdsj:function () {
    if (this.data.gqInfo.isShop == 1) {
      wx.navigateTo({
        url: 'shangpu?longUID='+this.data.gqInfo.gqInfo.Uid
      })      
    }else{
      this.showModalty('此商家未开通商铺') 
    }
  },
  changePic:function (e) {
    var id = e.currentTarget.dataset.id;
    // if (this.data.is_vod == 3) {
    //   this.setData({
    //     is_show:false
    //   })
    // }else{
    //   this.setData({
    //     is_vod:true
    //   })
    // }
    if (this.data.is_show) {
       this.setData({
        is_show:false
      })     
     }else{
        this.setData({
        is_show:true
      })      
     }
  },
  scsj:function () {      
      var that = this     
      if (this.data.scsj == '') {
        if (app.checkFjLogin()) {
            var FjLoginLog = wx.getStorageSync('FjLoginLog');           
            var api_input = {
              strUID:FjLoginLog.UID,
              strUpw:FjLoginLog.UPwd,              
              gqid:this.data.gqid,
              DoAction:1,
              gqType:1,
              strRSA:app.data.strRSA
            }
            app.getDaoPostOld('api/FeijiuApp/MyGqShouC_Add',api_input,function (res) {              
              if (res.code == 200) {
                that.setData({
                  scsj:'color: #fff',
                  scsjbg:'background: #0cc783;border:solid 1px #0cc783'
                })
                that.showModalty('商机收藏成功,可以去个人中心我的收藏去查看全部收藏')
              }else{                
                that.showModalty(res.data.message)           
              }
            })
        }else{
           wx.navigateTo({ url: '../../pages/login/index' }); 
        }
      }else{        
            var FjLoginLog = wx.getStorageSync('FjLoginLog');           
            var api_input = {
              strUID:FjLoginLog.UID,                         
              gqid:this.data.gqid,              
              strRSA:app.data.strRSA,
              gqType:1
            }
            app.getDaoPostOld('api/FeijiuApp/MyZcShouC_DelByGqid',api_input,function (res) {
                     
              if (res.code == 200) {
                that.setData({
                  scsj:'',
                  scsjbg:''
                }) 
                that.showModalty('商机解除收藏成功') 
              }else{
                that.showModalty('商机解除收藏失败,请确认您是否登录')   
              }
            })
      }
  },
  cklxfs:function () {   
    var that = this;
    if (app.checkFjLogin()) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog');
      app.getDaoPost('api/FeijiuApp/Feijiu_GetGqLxfs_Jm', {
        strUID: FjLoginLog.UID,
        strUpw:FjLoginLog.UPwd,
        strGqid:that.data.gqid,
        strRSA:''
      }, r => {
        if (r.code == 200) {
          var result = JSON.parse(app.aesDec(r.data.GqInfo));
          if (result.ErrNum == 111) {
            that.setData({
              LoginUserRankName:result.LoginUserRankName,
              AllLookNum:result.AllLookNum,
              HaveLookNum:result.HaveLookNum,
              NextRankName:result.NextRankName
            })
            that.showDialogBtn();
          }else if (result.ErrNum == 11 || result.ErrNum == 1) {
            that.setData({
              ComName:result.ComName,
              LinkMan:result.LinkMan,
              ComAddress:result.ComAddress,
              Mobile:result.Mobile,
              ComPhone:result.ComPhone
            })
            that.showModaltel()
          }else{
           that.showModalty('您没有权限查看该联系方式,了解更多请联系客服人员')
          }
        }
      })



      return
      var url = 'api/FeijiuApp/GetGqLxfs_Jm?strUID='+FjLoginLog.UID+'&strUpw='+FjLoginLog.UPwd+'&strGqid='+this.data.gqid+'&strRSA=';
      app.getDaoGet(url,function (r) {
        if (r.code == 200) {
          var result = JSON.parse(app.aesDec(r.data));
          if (result.ErrNum == 111) {
            that.setData({
              LoginUserRankName:result.LoginUserRankName,
              AllLookNum:result.AllLookNum,
              HaveLookNum:result.HaveLookNum,
              NextRankName:result.NextRankName
            })
            that.showDialogBtn();
          }else if (result.ErrNum == 11 || result.ErrNum == 1) {
            that.setData({
              ComName:result.ComName,
              LinkMan:result.LinkMan,
              ComAddress:result.ComAddress,
              Mobile:result.Mobile,
              ComPhone:result.ComPhone
            })
            that.showModaltel()
          }else{
           that.showModalty('您没有权限查看该联系方式,了解更多请联系客服人员')
          }
        }
        
      })
    }else{
      wx.navigateTo({ url: '../../pages/login/index' }); 
    }   
  },  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var gqid = options.gqid;
    // var gqid = '5557008';
    this.setData({
      gqid:gqid
    })
    // var that = this
    // var FjLoginLog = wx.getStorageSync('FjLoginLog');
    // if (FjLoginLog) {
    //   var api_input ={
    //     strID:gqid,
    //     longUID:FjLoginLog.UID
    //   }      
    //   that.setData({
    //     islogInActive:true
    //   })
    // }else{
    //   var api_input ={
    //     strID:gqid
    //   }
    //   that.setData({
    //     islogInActive:false
    //   })
    // }    
    // app.getDaoPost('api/FeijiuApp/Post_FJ_GetGQMInfo',api_input,function (res) {
    //   console.log(res)
    //   if (res.code == 200) {
    //     var info = res.data;
    //         info.gqInfo.FbDate = info.gqInfo.FbDate.replace('T', " ")
    //     that.setData({
    //       gqInfo: info,
    //       IsVideo:res.data.IsVideo,
    //       // phonelist:info.gqInfo.Photo.split(",")
    //       phonelist:app.phoneSplit(info.gqInfo.Photo)
    //     }) 

    //     if ((info.gqInfo.Photo.length > 6) && (info.gqInfo.Video.length > 6)) {
    //       that.setData({
    //         is_vod:3
    //       })
    //     }else if ((info.gqInfo.Photo.length > 6) && (info.gqInfo.Video.length < 6)) {
    //       that.setData({
    //         is_vod:1,
    //         is_show:true,
    //       })
    //     }else if ((info.gqInfo.Photo.length < 6) && (info.gqInfo.Video.length > 6)) {
    //       that.setData({
    //         is_vod:2,
    //         is_show:false,
    //       })
    //     }

    //     if (res.data.IsSC == 1) {
    //       that.setData({
    //         scsj:'color: #fff',
    //         scsjbg:'background: #0cc783;border:solid 1px #0cc783'
    //       })          
    //     }else{
    //       that.setData({
    //         scsj:'',
    //         scsjbg:''
    //       })           
    //     }
    //     if (res.data.isShop == 1) {
    //       that.setData({
    //         sdsj:'color: #fff',
    //         sdsjbg:'background: #0cc783;border:solid 1px #0cc783'
    //       })          
    //     }else{
    //       that.setData({
    //         sdsj:'',
    //         sdsjbg:''
    //       })           
    //     }



    //   }
    // })
  },
  toF5(){
    this.onShow()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo');
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    let gqid = that.data.gqid
    let gqInfo = that.data.gqInfo
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    if (FjLoginLog) {
      var api_input ={
        strID:gqid,
        longUID:FjLoginLog.UID
      }      
      that.setData({
        islogInActive:true
      })
    }else{
      var api_input ={
        strID:gqid
      }
      that.setData({
        islogInActive:false
      })
    }    
    app.getDaoPost('api/FeijiuApp/Post_FJ_GetGQMInfo',api_input,function (res) {
      console.log(res)
      if (res.code == 200) {
        var info = res.data;
            info.gqInfo.FbDate = info.gqInfo.FbDate.replace('T', " ")
        that.setData({
          gqInfo: info,
          IsVideo:res.data.IsVideo,
          // phonelist:info.gqInfo.Photo.split(",")
          phonelist:app.phoneSplit(info.gqInfo.Photo)
        }) 

        if ((info.gqInfo.Photo.length > 6) && (info.gqInfo.Video.length > 6)) {
          that.setData({
            is_vod:3
          })
        }else if ((info.gqInfo.Photo.length > 6) && (info.gqInfo.Video.length < 6)) {
          that.setData({
            is_vod:1,
            is_show:true,
          })
        }else if ((info.gqInfo.Photo.length < 6) && (info.gqInfo.Video.length > 6)) {
          that.setData({
            is_vod:2,
            is_show:false,
          })
        }

        if (res.data.IsSC == 1) {
          that.setData({
            scsj:'color: #fff',
            scsjbg:'background: #0cc783;border:solid 1px #0cc783'
          })          
        }else{
          that.setData({
            scsj:'',
            scsjbg:''
          })           
        }
        if (res.data.isShop == 1) {
          that.setData({
            sdsj:'color: #fff',
            sdsjbg:'background: #0cc783;border:solid 1px #0cc783'
          })          
        }else{
          that.setData({
            sdsj:'',
            sdsjbg:''
          })           
        }



      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function( options ){
  　　var that = this;  　　
  　　var shareObj = {
  　　　　title: this.data.gqInfo.gqInfo.Title,     
  　　　　path: '/pages/gongqiuxinxi/detailed?gqid='+this.data.gqid,    
  　　　　imgUrl: '',
  　　};  　
  　　if( options.from == 'button' ){
  　　　　shareObj.path = '/pages/gongqiuxinxi/detailed?gqid='+this.data.gqid;
  　　}  　　
  　　return shareObj;
  },
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  }, 
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  onCancel: function () {
    this.hideModal();
  },   
  onConfirm: function () {
    this.hideModal();
    wx.showToast({
      title: "加载中",
      icon: "loading",      
    })    
    var that = this
    var FjLoginLog = wx.getStorageSync('FjLoginLog')      

    app.getDaoPost('api/FeijiuApp/Feijiu_GetGqLxfsInfo_Jm', {
      strUID: FjLoginLog.UID,
      strUpw:FjLoginLog.UPwd,
      strGqid:that.data.gqid,
      strRSA:app.data.strRSA
    }, res => {
      var result = JSON.parse(app.aesDec(res.data.GqInfo));
      wx.hideToast()
      if (result.ErrNum == 1) {
        that.setData({
            ComName:result.ComName,
            LinkMan:result.LinkMan,
            ComAddress:result.ComAddress,
            Mobile:result.Mobile,
            ComPhone:result.ComPhone
        })
        that.showModaltel();
      }
    })
    return
    wx.request({        
      url:app.data.api_url+"api/FeijiuApp/GetGqLxfsInfo_Jm?strUID="+FjLoginLog.UID+"&strUpw="+FjLoginLog.UPwd+"&strGqid="+that.data.gqid+"&strRSA="+app.data.strRSA,
        success: function(res) { 
        var result = JSON.parse(app.aesDec(res.data.data));
        wx.hideToast()
        if (result.ErrNum == 1) {
          that.setData({
              ComName:result.ComName,
              LinkMan:result.LinkMan,
              ComAddress:result.ComAddress,
              Mobile:result.Mobile,
              ComPhone:result.ComPhone
          })
          that.showModaltel();
        }
      }
    })    
  },   
  showModaltel:function () {
    this.setData({
      showModaltel:true
    })
  },
  onCanceltel:function () {
    this.setData({
      showModaltel:false
    })
  },

  onCancelty:function () {
    this.setData({
      showModalty:false
    })
  },
  showModalty:function (tishi) {
    this.setData({
      showModalty:true,
      showModaltyContent:tishi
    })
  },
  preventTouchMove:function () {
    // body...
  },
  fuwudianhua:function(){
    wx.makePhoneCall({
      phoneNumber: '0311-87106666'
    })
  }  
})